package lion.test.mvc;

import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lion.framework.core.web.path.PathNodeMapping;
import lion.framework.core.web.path.PathNode;
import lion.framework.core.web.path.PathNodeExecutor;

public class ActionInvocation {

	private FilterChain chain;
	private String path;

	private int currentInterceptor = 0;

	public void invoke(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Interceptor[] interceptors = new Interceptor[0];
		Interceptor interceptor = interceptors[currentInterceptor];
		if (interceptor != null) {
			currentInterceptor++;
			interceptor.intercept(request, response, this);
		}
		PathNode node = PathNodeMapping.find(path);
		if (node != null && node.getMethod() != null) {
			new PathNodeExecutor(node).execute(request, response);
		} else {
			chain.doFilter(request, response);
		}
	}
}
